package com.example.activiti.demo.service;

import com.example.activiti.demo.entity.SysRole;
import com.example.activiti.demo.entity.SysUser;
import com.example.activiti.demo.util.ActivitiUserUtil;
import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.GroupQuery;
import org.activiti.engine.impl.GroupQueryImpl;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.interceptor.Session;
import org.activiti.engine.impl.persistence.entity.GroupEntity;
import org.activiti.engine.impl.persistence.entity.GroupEntityManager;
import org.springframework.context.annotation.Lazy;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: cheng
 * @date: 2020/2/21 17:07
 */


@Service
public class CustomGroupEntityManager implements GroupEntityManager, Session {

    @Resource
    private SysRoleService sysRoleService;

    @Resource
    private SysUserService sysUserService;


    @Override
    public List<Group> findGroupByQueryCriteria(GroupQueryImpl groupQuery, Page page) {
        return null;
    }

    @Override
    public long findGroupCountByQueryCriteria(GroupQueryImpl groupQuery) {
        return 0;
    }

    @Override
    public List<Group> findGroupsByUser(String userId) {
        if (userId == null) {
            return null;
        }
        try {
            SysUser sysUser = sysUserService.getById(userId);
            String[] split = sysUser.getRoleId().split(",");
            List<Group> list = new ArrayList<>();
            for (String id : split) {
                list.add(ActivitiUserUtil.toActivitiGroup(id));
            }
            return list;
        } catch (EmptyResultDataAccessException e) {
            return null;
        }
    }

    @Override
    public List<Group> findGroupsByNativeQuery(Map<String, Object> map, int i, int i1) {
        return null;
    }

    @Override
    public long findGroupCountByNativeQuery(Map<String, Object> map) {
        return 0;
    }


    @Override
    public GroupEntity findById(String s) {
        SysRole byId = sysRoleService.getById(s);
        return ActivitiUserUtil.toActivitiGroup(byId.getId());
    }


    @Override
    public Group createNewGroup(String s) {
        return null;
    }

    @Override
    public GroupQuery createNewGroupQuery() {
        return null;
    }

    @Override
    public void flush() {
    }

    @Override
    public void close() {

    }

    @Override
    public boolean isNewGroup(Group group) {
        return false;
    }


    @Override
    public GroupEntity create() {
        return null;
    }


    @Override
    public void insert(GroupEntity entity) {

    }

    @Override
    public void insert(GroupEntity entity, boolean b) {

    }

    @Override
    public GroupEntity update(GroupEntity entity) {
        return null;
    }

    @Override
    public GroupEntity update(GroupEntity entity, boolean b) {
        return null;
    }

    @Override
    public void delete(String s) {

    }

    @Override
    public void delete(GroupEntity entity) {

    }

    @Override
    public void delete(GroupEntity entity, boolean b) {

    }
}

